Skip to contents

Applies a function to a single part. When the part is stored as a model_spec, fn can change it with the term helpers.

Usage

modify_part(spec, i, fn)

Arguments

spec

A model_spec object.

i

The position of the part: 1 is the first part after the main terms.

fn

A function of one argument, applied to the stored part; its return value replaces it, and NULL removes it.

Value

A new model_spec with the part replaced.

See also

Examples

m <- model_spec(x1) |> set_parts(model_spec(firm))
modify_part(m, 1, \(p) add_terms(p, year))
#> model_spec: ~ x1 | firm + year